package com.example.controller;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.AutoLog;
import com.example.common.Result;
import com.example.domain.entity.Orders;
import com.example.domain.entity.Params;
import com.example.domain.entity.Reserve;
import com.example.domain.entity.Room;
import com.example.domain.vo.OrdersVo;
import com.example.service.OrderService;
import com.example.service.RoomService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@CrossOrigin
@RestController
@RequestMapping("/orders")
public class OrdersController {

    private static final Logger log = LoggerFactory.getLogger(OrdersController.class);

    @Autowired
    private OrderService orderService;
    
    @PostMapping("/add")
    public Result addOrders(@RequestBody OrdersVo vo){
        return orderService.addOrders(vo);
    }

    @PutMapping("/pay")
    public Result pay(@RequestBody Orders orders){
        return orderService.pay(orders);
    }

    @GetMapping("/list")
    public Result list(Params params){
        Page<OrdersVo> page = orderService.findBySearch(params);
        return Result.success(page);
    }

    @PostMapping("/confirm")
    public Result confirm(@RequestBody Orders orders) {
        orderService.confirm(orders);
        return Result.success();
    }

    @PostMapping("/cancel")//用户点击取消预约按钮修改状态 已修改
    public Result cancel(@RequestBody Orders orders) {
        orderService.cancel(orders);
        return Result.success();
    }

    @PostMapping("/pass")//员工点击通过按钮修改状态（通过取消预约）  已修改
    public Result pass(@RequestBody Orders orders) {
        orderService.pass(orders);
        return Result.success();
    }

}
